package com.hp.monitoring.pingmon.web.server;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.hp.monitoring.pingmon.Host;
import com.hp.monitoring.pingmon.HostImpl;
import com.hp.monitoring.pingmon.HostPool;
import com.hp.monitoring.pingmon.Monitor;
import com.hp.monitoring.pingmon.web.client.Node;


/**
 * Servlet implementation class for Servlet: PingMonServlet
 *
 */
 public class PingMonServlet extends com.google.gwt.user.server.rpc.RemoteServiceServlet implements javax.servlet.Servlet, 
 				com.hp.monitoring.pingmon.web.client.MonitorService {

	private static final long serialVersionUID = 1L;

	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public PingMonServlet() {
		super();
	}

	public com.hp.monitoring.pingmon.web.client.Host getPool() {
		
		WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		Monitor m = (Monitor)context.getBean("Monitor");
		
		ArrayList<Host> hosts = new ArrayList<Host>();
		  
		try {
			Host h = new HostImpl();
			h.setAddress(InetAddress.getByName("router"));
			hosts.add(h);
			h.setAddress(InetAddress.getByName("192.168.0.43"));
			hosts.add(h);
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		HostPool pool = m.createHostPool("home", hosts);
		com.hp.monitoring.pingmon.web.client.Host h = new com.hp.monitoring.pingmon.web.client.Host();
		h.name = "Router";
		Node n = new Node();
		n.name = "router";
		n.active = true;
		h.nodes.add(n);
		n = new Node();
		n.name = "192.168.0.43";
		n.active = false;
		h.nodes.add(n);
		return h;
	}   	
	
	
	  	    
}